#策略模式



#三、策略模式的优点和应用场景
#优点：
#1、各个策略可以自由切换：这也是依赖抽象类设计接口的好处之一；2、减少代码冗余；3、扩展性优秀，移植方便，使用灵活。

#应用场景：
#1、算法策略比较经常地需要被替换时，可以使用策略模式。如现在超市前台，会常遇到刷卡、某宝支付、某信支付等方式，就可以参考策略模式。
class customer:
    customer_name = ""
    snd_way = ""
    info = ""
    phone = ""
    email = ""

    def setPhone(self, phone):
        self.phone = phone

    def setEmail(self, mail):
        self.email = mail

    def getPhone(self):
        return self.phone

    def getEmail(self):
        return self.email

    def setInfo(self, info):
        self.info = info

    def setName(self, name):
        self.customer_name = name

    def setBrdWay(self, snd_way):
        self.snd_way = snd_way

    def sndMsg(self):
        self.snd_way.send(self.info)


class msgSender:
    dst_code = ""

    def setCode(self, code):
        self.dst_code = code

    def send(self, info):
        pass


class emailSender(msgSender):
    def send(self, info):
        print ("EMAIL_ADDRESS:%s EMAIL:%s" % (self.dst_code, info))



class textSender(msgSender):
    def send(self, info):
        print ("TEXT_CODE:%s EMAIL:%s" % (self.dst_code, info))


if __name__ == "__main__":
    customer_x = customer()
    customer_x.setName("CUSTOMER_X")
    customer_x.setPhone("10023456789")
    customer_x.setEmail("customer_x@xmail.com")
    customer_x.setInfo("Welcome to our new party!")
    text_sender = textSender()
    text_sender.setCode(customer_x.getPhone())
    customer_x.setBrdWay(text_sender)
    customer_x.sndMsg()
    mail_sender = emailSender()
    mail_sender.setCode(customer_x.getEmail())
    customer_x.setBrdWay(mail_sender)
    customer_x.sndMsg()

